<?php
/**
 * Short description for file.
 *
 * This file is application-wide controller file. You can put all
 * application-wide controller-related methods here.
 *
 * PHP versions 4 and 5
 *
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 * Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
 * @link          http://cakephp.org CakePHP(tm) Project
 * @package       cake
 * @subpackage    cake.app
 * @since         CakePHP(tm) v 0.2.9
 * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 */

/**
 * Short description for class.
 *
 * Add your application-wide methods in the class below, your controllers
 * will inherit them.
 *
 * @package       cake
 * @subpackage    cake.app
 */
class AppController extends Controller {
	
	var $components = array('Snapuser', 'Session', 'Snapfacebook', 'Snaptwitter', 'Amazon');
	var $helpers = array("Js", "Snapajax", "Html", "Session", "Snapuser", "Snapfacebook");

	
	function redirectHome()	{
		$this->redirect(array('controller' => 'pages', 'action' => 'display', 'home'));
	}
	
	function redirectLogin()	{
		$this->redirect(array('controller' => 'users', 'action' => 'login'));
	}
	
	function redirectIfLoggedIn()	{
		if ($this->Snapuser->isLoggedIn()) $this->redirect(array('action' => 'profil'));
	}
	
	function beforeFilter()	{
		$this->Snapuser->setOptions();
		if (IS_LOCALHOST){
			$this->Snapuser->useFacebook('183266121710885', '644340d0c5a554782d24734265142349', 'facebook_uid');
			$this->Snapuser->useTwitter('br6EjUW8FSO7dBWDwLfnSQ', 'JZMU5rEz1TyNpVkM92QCVpbc5yQ0S3Mqwuv4gK1c', 'twitter_uid');
		} elseif(IS_DEV)	{
			$this->Snapuser->useFacebook('203702732973488', '49e90a6a3591b87a60bf4bd9077a10fb', 'facebook_uid');
			$this->Snapuser->useTwitter('PujKUq1OdfEka0Us0yFFg', 'uWORuEzWtZol6S9SwunbsLIqKu8dQBsUk6sVc1lJWU', 'twitter_uid');
		} else {
			$this->Snapuser->useFacebook('149800371748253', '027caf889a553bf140358f72a9881346', 'facebook_uid');
			$this->Snapuser->useTwitter('IfMeLi73VZbz4eghrlbHg', 'fMlzXdaCbAPKSyIVLotmMvD91PKbITdlRl2EMIQqc', 'twitter_uid');
		}
		$this->Snapuser->getUser();
		
		$this->Amazon->setOptions('AKIAIN5747E3EH2CNO5Q', 'Gjsdcs3+Wvvxahad0PyfQnXGHbVhgMgwcndR3ezC');
		
	
		if ($this->Snapuser->newFacebookUser())	{ // new users have to complete their new profil
			if ($this->params['controller'] != 'users' || $this->params['action'] != 'signup')	
				$this->redirect(array('controller' => 'users', 'action' => 'signup'));
		}
		
	
		if ($this->Snapuser->newTwitterUser())	{ // new users have to complete their new profil
			if ($this->params['controller'] != 'users' || $this->params['action'] != 'signup')	
				$this->redirect(array('controller' => 'users', 'action' => 'signup'));
		}
	}
}
?>